//2009/10/17 15:21:01
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

int inf = 2100000000;
class EnemyTowers
{
public:
    int attack(int myUnits, int hpT, int attackT, int numWodT, int numStoT)
    {
        int left = 1;
        int right = myUnits-1;
        int count = inf;
        while (left <= right)
        {
            int num1 = (left + right) / 2;
            int num2 = myUnits - num1;
            int count1 = tack(num1, hpT, attackT, numWodT);
            int count2 = tack(num2, hpT, attackT, numStoT);
			cout << num1 << ", " << num2 << ", " << count1 << ", " << count2 << endl;
            if (count1 == inf && count2 == inf) return -1;
            else if (count1 > count2 ) left = num1 + 1;
            else if (count2 >= count1 ) right = num1 - 1;
            //else right = num1 - 1;
            if (count1 != inf && count2 != inf)
            {
                if (count == inf)
                    count = max(count1, count2);
                else
                    count = min(count, max(count1, count2));
            }
        }
		if(count == inf) return -1;
        return count;
    }
    int tack(int units, int hpT, int attack, int num)
    {
        int att = 0;
        int count = 0;
        while (num > 0 && units > 0)
        {
            count ++;
            att += units;
            int reduce = att / hpT;
            num -= reduce;
            //cout << num << endl;
            if (num <= 0)
                break;
            units -= num * attack;
            att -= reduce * hpT;
            if (units <=0)
                return inf;
        }
		if(units <= 0) return inf;
        return count;
    }
};

